package com.lzb.convert.util;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

public class ConverterUtil {

	/** 
     * 把中文转成Unicode码 
     * @param str 
     * @return 
     */  
    public static String chnToUnicode(String str){  
        String result="";  
        for (int i = 0; i < str.length(); i++){  
            int chr1 = (char) str.charAt(i);  
            if(chr1>=19968&&chr1<=171941){//汉字范围 \u4e00-\u9fa5 (中文)  
                result+="\\u" + Integer.toHexString(chr1);  
            }else{  
                result+=str.charAt(i);  
            }  
        }  
        return result;  
    }  
    
    /**
     * 对中文进行转码
     * @param str
     * @return
     * @throws UnsupportedEncodingException 
     */
    public static String chnToEncode(String str) throws UnsupportedEncodingException {
    		return URLEncoder.encode(str, "UTF-8");
    }
    
}
